/**
 * @name: writeOffService
 * @Description:
 * @Author: 方琦
 * @Date: 2022/8/22 15:52
 **/
import axios from "../utils/axios";
import api from "../api";

//根据条件查询商品
export function SEARCH_ByUserInput(obj) {
    return new Promise((resolve, reject) => {
        axios({
            url: api.writeOffApi.SEARCH_ByUserInput,
            method: "post",
            params: obj
        }).then(res => {
            resolve(res.data)
        }).catch(err => {
            reject(err)
        })
    })
}

//编辑小类
export function UPDATE_SmallClass(small_class_goods_id, name) {
    return new Promise((resolve, reject) => {
        axios({
            url: api.writeOffApi.UPDATE_SmallClass,
            method: "post",
            params: {small_class_goods_id, name}
        }).then(res => {
            resolve(res.data)
        }).catch(err => {
            reject(err)
        })
    })
}

//删除小类
export function DEL_SmallClass(small_class_goods_id) {
    return new Promise((resolve, reject) => {
        axios({
            url: api.writeOffApi.DEL_SmallClass,
            method: "post",
            params: {small_class_goods_id}
        }).then(res => {
            resolve(res.data)
        }).catch(err => {
            reject(err)
        })
    })
}

//添加小类
export function ADD_SmallClass(product_categories_id, name) {
    return new Promise((resolve, reject) => {
        axios({
            url: api.writeOffApi.ADD_SmallClass,
            method: "post",
            params: {product_categories_id, name}
        }).then(res => {
            resolve(res.data)
        }).catch(err => {
            reject(err)
        })
    })
}

//修改商品大类
export function UPDATE_BigClass(obj) {
    return new Promise((resolve, reject) => {
        axios({
            url: api.writeOffApi.UPDATE_BigClass,
            method: "post",
            params: obj
        }).then(res => {
            resolve(res.data)
        }).catch(err => {
            reject(err)
        })
    })
}

//删除商品大类
export function DEL_BigClass(product_categories_id) {
    return new Promise((resolve, reject) => {
        axios({
            url: api.writeOffApi.DEL_BigClass,
            method: "post",
            params: {product_categories_id}
        }).then(res => {
            resolve(res.data)
        }).catch(err => {
            reject(err)
        })
    })
}

//添加商品大类
export function ADD_BigClass(name) {
    return new Promise((resolve, reject) => {
        axios({
            url: api.writeOffApi.ADD_BigClass,
            method: "post",
            params: {name}
        }).then(res => {
            resolve(res.data)
        }).catch(err => {
            reject(err)
        })
    })
}

//新增商品
export function ADD_Goods(obj) {
    return new Promise((resolve, reject) => {
        axios({
            url: api.writeOffApi.ADD_Goods,
            method: "post",
            params: obj
        }).then(res => {
            resolve(res.data)
        }).catch(err => {
            reject(err)
        })
    })
}

//获取商品小类
export function GET_SmallClass(product_categories_id) {
    return new Promise((resolve, reject) => {
        axios({
            url: api.writeOffApi.GET_SmallClass,
            method: "post",
            params: {product_categories_id}
        }).then(res => {
            resolve(res.data);
        }).catch(err => {
            reject(err)
        })
    })
}

//获取商品大类
export function GET_BigClass() {
    return new Promise((resolve, reject) => {
        axios({
            url: api.writeOffApi.GET_BigClass,
            method: "post"
        }).then(res => {
            resolve(res.data);
        }).catch(err => {
            reject(err)
        })
    })
}

//批量删除商品
export function DEL_MoreGoods(goods_ids) {
    return new Promise((resolve, reject) => {
        axios({
            url: api.writeOffApi.DEL_GoodsList,
            method: "post",
            params: goods_ids
        }).then(res => {
            resolve(res.data)
        }).catch(err => {
            reject(err)
        })
    })
}

//删除商品
export function DEL_GoodsList(goods_id) {
    return new Promise((resolve, reject) => {
        axios({
            url: api.writeOffApi.DEL_GoodsList,
            method: "post",
            params: {
                goods_id
            }
        }).then(res => {
            resolve(res.data)
        }).catch(err => {
            reject(err)
        })
    })
}

//获取商品列表
export function GET_GoodsList(currentPage, pageSize) {
    return new Promise((resolve, reject) => {
        axios({
            url: api.writeOffApi.GET_GoodsList,
            method: "post",
            params: {
                currentPage,
                pageSize
            }
        }).then(res => {
            resolve(res.data)
        }).catch(err => {
            reject(err)
        })
    })
}

//删除采购列表
export function DEL_Purchase(goods_id, id) {
    return new Promise((resolve, reject) => {
        axios({
            url: api.writeOffApi.DEL_Purchase,
            method: "post",
            params: {
                goods_id, id
            }
        }).then(res => {
            resolve(res.data)
        }).catch(err => {
            reject(err)
        })
    })
}

//获取采购列表
export function GET_Purchase(currentPage, pageSize) {
    return new Promise((resolve, reject) => {
        axios({
            url: api.writeOffApi.GET_Purchase,
            method: "post",
            params: {
                currentPage,
                pageSize
            }
        }).then(res => {
            resolve(res.data)
        }).catch(err => {
            reject(err)
        })
    })
}

//编辑供应商
export function UPDATE_Supplier(id, formDate) {
    return new Promise((resolve, reject) => {
        axios({
            url: api.writeOffApi.UPDATE_Supplier,
            method: "post",
            params: {
                id, ...formDate
            }
        }).then(res => {
            resolve(res.data)
        }).catch(err => {
            reject(err)
        })
    })
}

//添加供应商
export function ADD_Supplier(formTable) {
    return new Promise((resolve, reject) => {
        axios({
            url: api.writeOffApi.ADD_Supplier,
            method: "post",
            params: formTable
        }).then(res => {
            resolve(res.data)
        }).catch(err => {
            reject(err)
        })
    })
}

//供应商按条件搜索
export function SEARCH_Supplier_ByInput(currentPage, pageSize, string) {
    return new Promise((resolve, reject) => {
        axios({
            url: api.writeOffApi.SEARCH_Supplier_ByInput,
            method: "post",
            params: {currentPage, pageSize, string}
        }).then(res => {
            resolve(res.data)
        }).catch(err => {
            reject(err)
        })
    })
}

//删除供应商
export function DEL_Supplier(id) {
    return new Promise((resolve, reject) => {
        axios({
            url: api.writeOffApi.DEL_Supplier,
            method: "post",
            params: {id}
        }).then(res => {
            resolve(res.data)
        }).catch(err => {
            reject(err)
        })
    })
}

//获取供应商列表
export function GER_SupplierList(currentPage, pageSize) {
    return new Promise((resolve, reject) => {
        axios({
            url: api.writeOffApi.GER_SupplierList,
            method: "post",
            params: {
                currentPage, pageSize
            }
        }).then(res => {
            resolve(res.data)
        }).catch(err => {
            reject(err)
        })
    })
}

//编辑仓库
export function UPDATE_WareHouse(obj) {
    return new Promise((resolve, reject) => {
        axios({
            url: api.writeOffApi.UPDATE_WareHouse,
            method: "post",
            params: obj
        }).then(res => {
            resolve(res.data)
        }).catch(err => {
            reject(err)
        })
    })
}

//删除仓库
export function DEL_WareHouse(id) {
    return new Promise((resolve, reject) => {
        axios({
            url: api.writeOffApi.DEL_WareHouse,
            method: "post",
            params: {id}
        }).then(res => {
            resolve(res.data)
        }).catch(err => {
            reject(err)
        })
    })
}

//添加仓库
export function ADD_WareHouse(obj) {
    return new Promise((resolve, reject) => {
        axios({
            url: api.writeOffApi.ADD_WareHouse,
            method: "post",
            params: {
                ...obj
            }
        }).then(res => {
            resolve(res.data)
        }).catch(err => {
            reject(err)
        })
    })
}

//获取仓库列表
export function get_WareHouseList() {
    return new Promise((resolve, reject) => {
        axios({
            url: api.writeOffApi.WareHouse_List,
            method: "post",
        }).then(res => {
            resolve(res.data)
        }).catch(err => {
            reject(err)
        })
    })
}

//销售记录
export function getSalesRecord(currentPage, pageSize) {
    return new Promise((resolve, reject) => {
        axios({
            url: api.writeOffApi.SALES_RECORD,
            method: "post",
            params: {
                currentPage,
                pageSize
            }
        }).then(res => {
            resolve(res.data)
        }).catch(err => {
            reject(err)
        })
    })
}
